from appium.webdriver.common.appiumby import AppiumBy
from AppTest.page.base_page import BasePage


class ClockPage(BasePage):

    __BUTTON_NEWRULE = (AppiumBy.XPATH, "//*[@text='新建规则']")
    __BUTTON_CLOCKPEOPLE = (AppiumBy.XPATH, "//*[@text='打卡人员']")
    # 选择第一个部门
    __BUTTON_DEPARTMENT = (AppiumBy.XPATH, "//*[@text='可选范围']/parent::*/parent::*/parent::*/following::*[1]")
    # 确定按钮
    __BUTTON_CONFIRM = (AppiumBy.XPATH, "//*[@text='确定']")
    # 规则名称按钮
    __BUTTON_RULENAME = (AppiumBy.XPATH, "//*[@text='规则名称']")
    # 规则名称输入框
    __INPUT_RULENAME = (AppiumBy.XPATH,
                        "//*[@text='规则名称']/parent::*/parent::*/parent::*/parent::*/parent::*/following::*[2]/child::*")
    # 规则类型按钮
    __BUTTON_RULETYPE = (AppiumBy.XPATH, "//*[@text='规则类型']")
    # 打卡位置按钮
    __BUTTON_POSITION = (AppiumBy.XPATH, "//*[@text='打卡位置']")
    # 保存按钮
    __BUTTON_SAVE = (AppiumBy.XPATH, "//*[@text='保存']")
    # 立即生效按钮
    __BUTTON_SAVENOW = (AppiumBy.XPATH, "//*[@text='立即生效']")
    # 规则按钮
    __BUTTON_RULE = (AppiumBy.XPATH, "//*[@text='规则']")

    __BUTTON_WC = (AppiumBy.XPATH, "//*[@text='外出打卡']")

    __BUTTON_CLOCK = (AppiumBy.ID, "com.tencent.wework:id/bfe")

    __BUTTON_MESSAGE = (AppiumBy.ID, "com.tencent.wework:id/si")


    def click_newrule(self):
        self.do_click(self.__BUTTON_NEWRULE)

    def click_clockpeople(self):
        self.do_click(self.__BUTTON_CLOCKPEOPLE)

    def click_department(self):
        self.do_click(self.__BUTTON_DEPARTMENT)

    def click_choosepeople(self, name):
        by = (AppiumBy.XPATH, f"//*[@text='{name}']")
        self.do_click(by)

    def click_confirm(self):
        self.do_click(self.__BUTTON_CONFIRM)

    def click_rulename(self):
        self.do_click(self.__BUTTON_RULENAME)

    def input_rulename(self, inputword):
        self.do_send_keys(self.__INPUT_RULENAME, inputword)

    def click_ruletype(self):
        self.do_click(self.__BUTTON_RULETYPE)

    def choose_ruletype(self, type):
        by = (AppiumBy.XPATH, f"//*[@text='{type}']")
        self.do_click(by)

    def click_position(self):
        self.do_click(self.__BUTTON_POSITION)

    def click_save(self):
        self.do_click(self.__BUTTON_SAVE)

    def click_savenow(self):
        self.do_click(self.__BUTTON_SAVENOW)

    def to_rule(self):
        self.do_click(self.__BUTTON_RULE)

    def click_wc(self):
        self.do_click(self.__BUTTON_WC)

    def clock(self):
        self.do_click(self.__BUTTON_CLOCK)

    def message(self):
        self.do_find(self.__BUTTON_MESSAGE).get_attribute("text")





